Xbasic in Desktop Applications

Description

Learn how to use Xbasic in Desktop applications.

Name
Description
A Tutorial in Xbasic for Desktop Applications

Xbasic is Alpha Anywheres built-in programming language. Out of the box, Alpha Anywhere is a powerful database and application development software package. You can use Alpha Anywhere for lots of different information management needs without doing any programming by using the Alpha Anywhere menus, commands, and Genies.

Addressing Types

There are four basic types of addressing available in Alpha Anywhere.

Canceling Events

All of the events whose names are prefixed with "Can" can be canceled, thus preventing the event from occurring. The CANCEL()command is used to cancel an event.

Developing Applications with Xbasic

An index of pages relating to developing applications in Xbasic.

"Maximum Stack Depth Exceeded" Error Message

The "maximum stack depth exceeded" error message can occur if you put a script on the OnFetch event and you scroll through records quickly, or if you put a script on a button and then press the button repeatedly. There may be other ways in which the error can occur. The error occurs because the script is invoked a second time before the current instance of the script has finished executing.

Parameters that Can be Passed to Global Functions

You can pass any Alpha Anywhere variable type to a Global Function. This includes variables of type:

Preventing an Event From Firing Twice

Sometimes an object's event will fire more than once. If this causes your code to run more than once, the following strategy will fix the problem. In your autoexec script add the following code.

Retrieving a Pointer to a Control

There are several ways to get the pointer to the control. The first way is to use the .CHILD() method and name the control. These examples refer to a button control, but other types of controls work the same way.

Scripts vs Functions

Scripts and functions are different in several important aspects.

Setting the Script Recording Level

You can determine whether the Script Recorder records operations (such as Append, Copy, Export etc.) as Low level, or high level Xbasic commands. For example:

Auto-Load Compiled Library

Here is an example of how you might use the Auto-Load Compiled Library: Say that you have developed an application called MyApp (the database is called MyApp.adb ). You are now ready to distribute your application to your customers, but you want to make sure that they cannot see any of the source code of your application.

Using Ask Variables

In this example, you will create an Xbasic script that prompts the user for the name of the customer, and then prints the corresponding mailing label. This lesson uses Xbasic scripting (not Action Scripting) and is intended for users with some experience with Xbasic.

Using the Xbasic Explorer to View Object Properties

To determine the list of properties associated with an object, use the Xbasic Explorer. To display the Xbasic Explorer, select View > Code editor from the Control Panel menu. For example, if you have a form called Customer, navigate in the Xbasic Explorer to Objects > Windows > Customer > Properties to see a list of the properties associated with the form (as shown below):

Using the Xbasic Window

By default, the Xbasic window shows the Raw Xbasic code for the operation. Raw Xbasic means the code shown is the exact code for the currently defined operation. It's a direct translation of what's in your Operation Card. The Raw Xbasic view is great for seeing what's going on behind-the-scenes when you are creating an Operation, but Raw Xbasic has little meaning outside the Operation Card. That's where the Processed Xbasic view comes in. Using the radio buttons, you can switch the view between Raw Xbasic, Processed Xbasic, and Processed without Confirmation dialogs.

Using Xbasic to Select a Record and Display a Form

Button1 runs Xbasic code that loads the Invoice form to display the details of the invoice selected in the embedded browse.

Viewing Xbasic Code Generated by a Procedure

Instructions for viewing Xbasic code generated by a procedure.

Writing Dialog Event Scripts

Web publishing applications only. Form event scripts provide an opportunity to respond to or process the input from a dialog (form) web component. You can run scripts when the following events occur.

Writing Expressions

When you pass an expression to a function or method, you are passing a line of Xbasic code as a character string. as result, whether the expression is used to filter or order records, whether it evaluates to a character or a logical value, the argument is type C (character). There are several principles that you should understand when writing an expression argument.

Xbasic Change Record

The Xbasic Change Record action changes the contents of a record without opening a form or browse. The user does not have to be aware that changes are being made.

Xbasic Script Context

When you run a script that is attached to a toolbar button, the script has the same context as the active window. The aliases this and parentform, used in a script attached to a toolbar button, refers to the active window. For example, assume that you have a toolbar with this Xbasic code attached to one of the buttons on the toolbar: